import React from "react";
import { Provider } from "react-redux";
import { applyMiddleware, combineReducers, createStore } from "redux";
import { createLogger } from "redux-logger";

import App from "./index";
import * as fromMain from "./pages/mainScreen/reducer";
import * as fromSearch from "./pages/searchScreen/reducer";
import { combineEpics, createEpicMiddleware } from "redux-observable";

const rootReducer = combineReducers({
  main: fromMain.reducer,
  search: fromSearch.reducer
});

const rootEpic = combineEpics(fromMain.epic);
const epicMiddleware = createEpicMiddleware();

const store = createStore(
  rootReducer,
  applyMiddleware(createLogger(), epicMiddleware)
);

epicMiddleware.run(rootEpic);

export const AppWithStore = () => (
  <Provider store={store}>
    <App />
  </Provider>
);
